import io.undertow.Handlers;
import io.undertow.Undertow;
import io.undertow.server.handlers.PathHandler;
import io.undertow.servlet.Servlets;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
import lombok.SneakyThrows;

/**
 * @author 80241997 - Liming.Shi
 */

public class DemoUndertow {

    @SneakyThrows
    public static void main(String[] args) {
        DeploymentInfo servletBuilder = Servlets.deployment()
                .setClassLoader(Servlets.class.getClassLoader())
                .setContextPath("/rebuild")
                .setDeploymentName("rebuild.war");

        DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);

        manager.deploy();

        PathHandler path = Handlers.path(Handlers.redirect("/rebuild"))
                .addPrefixPath("/rebuild", manager.start());

        Undertow server = Undertow.builder()
                .addHttpListener(8080, "0.0.0.0")
                .setHandler(path)
                .build();
        server.start();
    }
}
